package com.liyunhan.StrassenAlgorithm;

import java.util.Random;
import java.util.Scanner;

/**
 * @Description: 测试类
 * @Author: Liyunhan
 * @Date: 2021/11/15 22:19
 */
public class Test {
    public static void main(String[] args) {
        System.out.print("请输入矩阵大小(2^k): ");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        //生成矩阵二维数组
        double[][] matrix1 = new double[n][n];
        double[][] matrix2 = new double[n][n];

        //随机数类
        Random random = new Random();

        //使用随机数填充第一个数组
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrix1[i][j] = random.nextInt(10) * 10;
            }
        }
        printMatrix(matrix1, n);
        //使用随机数填充第二个数组
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrix2[i][j] = random.nextInt(10) * 10;
            }
        }
        printMatrix(matrix2, n);
        //1.实例化经典矩阵相乘算法类
        MatrixProduct matrixProduct = new MatrixProduct(n, matrix1, matrix2);
        double time1 = matrixProduct.start();
        double[][] resMatrix1 = matrixProduct.getResMatrix();
        System.out.println("经典矩阵算法运行时间为:" + time1);
        System.out.println("乘法结果为:");
        printMatrix(resMatrix1, n);

        //2.实例化Strassen矩阵相乘算法类
        MyStrassen myStrassen = new MyStrassen(n, matrix1, matrix2);
        double time2 = myStrassen.start();
        double[][] resMatrix2 = myStrassen.getResMatrix();
        System.out.println("Strassen矩阵算法运行时间为:" + time2);
        System.out.println("乘法结果为:");
        printMatrix(resMatrix2, n);

//        //3.实例化*优化的*Strassen矩阵相乘算法类
////        System.out.print("请输入任意偶数矩阵大小: ");
//        OptimStrassen optimStrassen = new OptimStrassen(n, matrix1, matrix2);
//        double time3 = optimStrassen.start();
//        double[][] resMatrix3 = optimStrassen.getResMatrix();
//        System.out.println("Strassen矩阵算法运行时间为:" + time3);
//        System.out.println("乘法结果为:");
//        printMatrix(resMatrix3, n);
//
//        //4.实例化*优化的*Strassen矩阵相乘算法类
////        System.out.print("请输入任意偶数矩阵大小: ");
//        OptimStrassen2 optimStrassen2 = new OptimStrassen2(n, matrix1, matrix2);
//        double time4 = optimStrassen2.prprocessing();
//        double[][] resMatrix4 = optimStrassen2.getResMatrix();
//        System.out.println("Strassen矩阵算法运行时间为:" + time4);
//        System.out.println("乘法结果为:");
//        printMatrix(resMatrix4, n);
    }

    /**
     * 打印矩阵元素公共方法
     *
     * @param matrix
     * @param n
     */
    public static void printMatrix(double[][] matrix, int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
    }
}
